<template>
  <div>
    <van-nav-bar
      title="搜索"
      left-text="返回"
      right-text="登录"
      left-arrow
      @click-left="onClickLeft"
      @click-right="onClickRight"
    />
    <van-search v-model="value" placeholder="请输入搜索关键词" @keydown.enter="search" />
    <template v-if="data!=[]">
      <van-card
        v-for="item in data"
        :key="item.id"
        num="2"
        price="2.00"
        desc="描述信息"
        :title="item.goodsname"
        :thumb="$pregImg+item.img"
      />
    </template>
      <div v-show="isshow">暂无数据</div>
  </div>
</template>

<script>
import { getSearch } from "../../request/api";
export default {
  data() {
    return {
      value: "",
      data: [],
      isshow:false
    };
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    onClickRight() {
      this.$router.push("/login");
    },
    search() {
      getSearch(this.value).then(res => {
        console.log(res);
        this.data = res.list;
        console.log(this.data);
        if(!this.data){
        this.isshow=true
      }
      });
    }
  },
  mounted() {
    this.value = this.$route.query.keywords;
    getSearch(this.value).then(res => {
      console.log(res);
      this.data = res.list;
      console.log(this.data);
      if(!this.data){
        this.isshow=true
      }
    });
  }
};
</script>

<style scoped>
.van-nav-bar__content {
  background-image: linear-gradient(180deg, #ff6040 0%, #ff8a80 100%);
}
</style>